home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / terminal / qterm-6.0 / qterm-6 / tty.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-25  |  3.2 KB  |  171 lines

  1. #ifndef lint
  2. static char RCSid[] = 
  3. "$Id: tty.c,v 6.1 1993/03/25 21:06:01 mcooper Exp mcooper $";
  4.  
  5. static char copyright[] =
  6. "@(#) Copyright (c) 1990-1993 Michael A. Cooper.\n\
  7.  All rights reserved.\n";
  8. #endif
  9.  
  10. /*
  11.  * Copyright (c) 1990-1993 Michael A. Cooper.
  12.  * This software may be freely distributed provided it is not sold for 
  13.  * profit and the author is credited appropriately.
  14.  */
  15.  
  16. /*
  17.  * Terminal interface routines
  18.  */
  19.  
  20. #include "config.h"
  21. #include "qterm.h"
  22. #include <stdio.h>
  23.  
  24. #if    !defined(STDIN_FILENO)
  25. #define STDIN_FILENO        0
  26. #endif
  27.  
  28. #if    TTY_TYPE == TTY_POSIX
  29. /*
  30.  * POSIX set terminal modes function
  31.  */
  32. struct termios            OrigTty;
  33.  
  34. int SetTtyModes()
  35. {
  36.     struct termios        newtty;
  37.  
  38.     if (tcgetattr(STDIN_FILENO, &OrigTty) != 0) {
  39.     Error("Cannot get tty modes: %s.", SYSERR);
  40.     Done(1);
  41.     /*NOTREACHED*/
  42.     }
  43.  
  44.     newtty = OrigTty;
  45.     newtty.c_iflag &= ~(INLCR|IGNCR);    /* ignore CR */
  46.     newtty.c_lflag &= ~(ECHO);        /* noecho */
  47.     newtty.c_lflag &= ~(ICANON);    /* crmode */
  48.     newtty.c_cc[VMIN] = 1;        /* crmode */
  49.     newtty.c_cc[VTIME] = 0;        /* crmode */
  50.  
  51.     if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &newtty) != 0) {
  52.     Error("Cannot set tty modes: %s", SYSERR);
  53.     Done(1);
  54.     /*NOTREACHED*/
  55.     }
  56.  
  57.     return(0);
  58. }
  59. #endif    /* TTY_SYSV */
  60.  
  61. #if    TTY_TYPE == TTY_SYSV
  62. /*
  63.  * System V set terminal modes function
  64.  */
  65. struct termio            OrigTty;
  66.  
  67. int SetTtyModes()
  68. {
  69.     struct termio        newtty;
  70.  
  71.     if (ioctl(STDIN_FILENO, TCGETA, &OrigTty) < 0) {
  72.     Error("Cannot get tty modes: %s.", SYSERR);
  73.     Done(1);
  74.     /*NOTREACHED*/
  75.     }
  76.  
  77.     newtty = OrigTty;
  78.     newtty.c_iflag &= ~(INLCR|IGNCR);    /* ignore CR */
  79.     newtty.c_lflag &= ~ECHO;        /* noecho */
  80.     newtty.c_lflag &= ~ICANON;        /* crmode */
  81.     newtty.c_cc[VMIN] = 1;        /* crmode */
  82.     newtty.c_cc[VTIME] = 0;        /* crmode */
  83.  
  84.     if (ioctl(STDIN_FILENO, TCSETAF, &newtty) < 0) {
  85.     Error("Cannot set tty modes: %s", SYSERR);
  86.     Done(1);
  87.     /*NOTREACHED*/
  88.     }
  89.  
  90.     return(0);
  91. }
  92. #endif    /* TTY_SYSV */
  93.  
  94. #if    TTY_TYPE == TTY_BSD
  95. /*
  96.  * BSD set terminal modes function
  97.  */
  98. struct sgttyb            OrigTty;
  99.  
  100. int SetTtyModes()
  101. {
  102.     struct sgttyb        newtty;
  103.  
  104.     if (ioctl(STDIN_FILENO, TIOCGETP, &OrigTty) < 0) {
  105.     Error("Cannot get tty modes: %s.", SYSERR);
  106.     Done(1);
  107.     /*NOTREACHED*/
  108.     }
  109.  
  110.     newtty = OrigTty;
  111.     newtty.sg_flags |= CBREAK;        /* crmode */
  112.     newtty.sg_flags &= ~ECHO;        /* noecho */
  113.  
  114.     if (ioctl(STDIN_FILENO, TIOCSETP, &newtty) < 0) {
  115.     Error("Cannot set tty modes: %s", SYSERR);
  116.     Done(1);
  117.     /*NOTREACHED*/
  118.     }
  119.  
  120.     return(0);
  121. }
  122. #endif    /* TTY_BSD */
  123.  
  124. #if    TTY_TYPE == TTY_POSIX
  125. /*
  126.  * POSIX restore terminal modes
  127.  */
  128. int UnSetTtyModes()
  129. {
  130.     if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &OrigTty) != 0) {
  131.     Error("Cannot restore tty modes: %s", SYSERR);
  132.     Done(1);
  133.     /*NOTREACHED*/
  134.     }
  135.  
  136.     return(0);
  137. }
  138. #endif    /* TTY_POSIX */
  139.  
  140. #if    TTY_TYPE == TTY_SYSV
  141. /*
  142.  * System V restore terminal modes
  143.  */
  144. int UnSetTtyModes()
  145. {
  146.     if (ioctl(STDIN_FILENO, TCSETAF, &OrigTty) < 0) {
  147.     Error("Cannot restore tty modes: %s", SYSERR);
  148.     Done(1);
  149.     /*NOTREACHED*/
  150.     }
  151.  
  152.     return(0);
  153. }
  154. #endif    /* TTY_SYSV */
  155.  
  156. #if    TTY_TYPE == TTY_BSD
  157. /*
  158.  * BSD restore terminal modes
  159.  */
  160. int UnSetTtyModes()
  161. {
  162.     if (ioctl(STDIN_FILENO, TIOCSETP, &OrigTty) < 0) {
  163.     Error("Cannot restore tty modes: %s", SYSERR);
  164.     Done(1);
  165.     /*NOTREACHED*/
  166.     }
  167.  
  168.     return(0);
  169. }
  170. #endif    /* TTY_BSD */
  171.